IF ELSEIF ENDIF
[[IF:logical_condition]] … [[ELSEIF]] … [[ENDIF]]
The actions associated with IF provide versatility to QuestDown automations. In short, by using IF and other commands (according to the syntax specified below), Events and Actions can be created that depend on certain Variables and may vary during the game. For example, a door might be closed, but after pulling a lever, it might become open. Or a monster might appear only after exploring a certain room, etc. In practical terms, this is achieved through one or more "If... then..." statements. For those unfamiliar with programming languages, understanding the principles used for IF and other commands may not be immediate. In these cases, it can be useful to see the examples below and use them as a starting point to develop your own automations.
Each Variable initially has a value of 0.
The IF action works by first performing a logical condition (see below). If the result of the logical condition is "True," the subsequent text is displayed and/or the actions present until the [[ELSEIF]]
or [[ENDIF]]
block are executed. If it is "False," the subsequent text is displayed and/or the actions present between the [[ELSEIF]]
and [[ENDIF]]
blocks are executed.
The [[ELSEIF]]
block is optional:
- Example 1:
{[[(P), ON_OPEN(R24)]] [[IF: GET(lever) = 1]] You unlocked the door by pulling the lever
before, so you can open the door! [[OPEN(S23)]] [[ELSEIF]] [[LOCKED]] [[ENDIF]]}
- Example 2:
{[[(K), ON_ENTER_ROOM:REPEAT]], [[ASK: Inside the room there is a lever.
,Do you want to pull it?]] You hear a strange sound from a nearby room [[SET(lever, 1]] [[END]]}
Logical Conditions
Logical conditions involve the use of special keywords such as: TURN
, RND
,QUEST_OBJECTIVE_COMPLETED
. In addition to these predefined keywords, it is possible to define Variables, which are names to which a value can be assigned and then used later in conditions.
These keywords must be compared with a value using logical operators =, <>, >, >=, <, <= with absolute values, such as numbers or texts. The operators allow checks that can result in "True" or "False".
- Example 1:
[[IF: GET(lever) = 1]]
- Example 2:
[[IF: TURN > 3]]
Below are some examples for various possibilities of using logical conditions with special keywords. For example, the code
Keywords and Logical Conditions
-
TURN
indicates the current turn of the game, so anIF
can be created to check if X turns have passed to perform an action or communicate a message to the players.- Example:
{[[(T), ON_NEW_TURN]] [IF: TURN > 20]] Too much time has passed,
your quest has failed! [[QUEST_FAILED]] [[ENDIF]]}
- Example:
ON_NEW_TURN
, it can be at any point on the board.
-
RND(FROM,TO)
is used to generate a random number, generating a number between the provided FROM and TO numbers.- Example:
{[[(A), ON_SEARCH_TREASURES]] [IF: RND(1,5) = 5]] You are lucky! You found 100 Gold coins!
[[ELSEIF]] You don’t find anything [[ENDIF]]}
- Example:
-
QUEST_OBJECTIVE_COMPLETED
is essentially a default Variable indicating whether the Quest objective has been reached. This operator is normally set to 0 unless the[[QUEST_OBJECTIVE_COMPLETED]]
action has been used previously, in which case it will have a value of 1.- Example:
{[[(U), ON_DEATH(P11)]]
[[IF: QUEST_OBJECTIVE_COMPLETED = 1]] You have successfully killed Grutgar and found the scroll
Now you can escape from the dungeon [[ELSEIF]] Oh no! You killed the evil wizard before finding the secret scroll
that you were sent to find. You have failed! [[QUEST_FAILED]] [[ENDIF]])]]}
- Example:
QUEST_OBJECTIVE_COMPLETED
is equal to 1, the text "You have successfully killed ..." appears; otherwise, the text "Oh no! you killed the evil wizard .." appears, and the Quest fails.
GET(name)
is used to retrieve the value of a variable previously assigned with[[SET(name,value)]]
.- Example:
{[[(A), ON_OPEN(N23)]] [[IF: GET(key) = 1]] You have the Key so you can open this door!
[[OPEN(S23)]] [[ELSEIF]] [[LOCKED]] [[ENDIF]]}
- Example:
{[[(A), ON_OPEN(O23)]] [[IF: GET(key) = 1]] [[ASK: Do you have the key?]] The door is now open
[[OPEN(S23)]] [[ELSE]] [[LOCKED]] [[END]] [[ELSEIF]] [[LOCKED]] [[ENDIF]]}
In this case, what happens is that after attempting to open the door, the phrase "Do you have the key?" appears, and only if the answer is yes, then the door will open. In all other cases, the door remains locked.